package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dao.SellDao;
import com.itheima.domain.Sell;
import com.itheima.service.SellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SellServiceimpl implements SellService {

    @Autowired
    private SellDao sellDao;

    @Override
    public IPage<Sell> top5() {
        LambdaQueryWrapper<Sell> lqw = new LambdaQueryWrapper<>();

        lqw.orderByDesc(Sell::getSales)
                .like(Sell::getGoodsName,"华为");
        IPage<Sell> sellIPage = new Page<>(1,5);

        return sellDao.selectPage(sellIPage, lqw);
    }

    @Override
    public void save(Sell sell) {
        sellDao.insert(sell);
    }

    @Override
    public void delete(Long id) {
        sellDao.deleteById(id);
    }

    @Override
    public void update(Sell sell) {
        sellDao.updateById(sell);
    }

    @Override
    public Sell selectById(Long id) {
        return sellDao.selectById(id);
    }


}
